home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-16 | 11.7 KB | 404 lines | [TEXT/KAHL] |
- /****
- * CNDImage.cp
- *
- * Methods for a persistent image type.
- *
- * Copyright © 1992 NeoLogic Systems. All rights reserved.
- *
- ****/
-
- #include "NeoTypes.h"
- #include CNeoStreamH
- #include CNeoMetaClassH
- #include CNeoNodeH
- #include CNeoDatabaseH
- #include "CNDImage.h"
- #include "CNDCamera.h"
-
- #ifndef NeoInherited
- #define NeoInherited CNeoBlob
- #endif
-
- CNDImage::CNDImage(void)
- {
- fExposure = 0;
- fFilm = 0;
- fFocal = 0;
- fFStop = 0;
- fCamera = 0;
- fKeyCount = 0;
- fName[0] = 0;
- fBy[0] = 0;
- fDate[0] = 0;
- fCatalog[0] = 0;
- }
-
- /*
- * Overriding this virtual method from the parent is an optimization which allows us
- * to avoid calling GetHandleSize().
- */
- #pragma segment NeoInfo
- long CNDImage::getLength(void) const
- {
- return kNDImageLength;
- }
-
- /*
- * This method returns the amount of file space the object occupies in the file. It
- * differs from the getLength() in that getLength returns the size of the object in
- * memory.
- */
- #pragma segment NeoInfo
- long CNDImage::getFileLength(void) const
- {
- return kNDImageFileLength;
- }
-
- /* ****************************************************************** */
- /** I/O Methods **/
- /* ****************************************************************** */
-
- /*
- * The readObject method is used to read in the permanent data members of the
- * object from the given stream. In most cases, this method operates without concern
- * for the type of stream the data values are coming from. As a result, this method
- * is capable of reading from such diverse sources as the data fork of a file, a
- * resource fork, an AppleEvent, the clipboard, a memory block, and so on.
- *
- * The aTag argument indicates how much information to read from the stream.
- * It is sometimes sufficient to read in a minimum amount of data and have all
- * other data be read in on demand. Other times it is necessary to read all the
- * data immediately as the stream may not be available later.
- *
- * The two tag values that are currently used are kNeoObjectTag and kNeoAllTag.
- *
- * The value kNeoObjectTag means that only those values of immediate interest
- * need to be read from the stream, though implementations of readObject may read
- * in additional data member values if they wish.
- *
- * The value kNeoAllTag indicates that all data member values for this class
- * should be read in to the stream.
- */
- #pragma segment NeoRead
- void CNDImage::readObject(CNeoStream *aStream, const NeoTag aTag)
- {
- short index;
-
- NeoInherited::readObject(aStream, 'PICT');
-
- fExposure = aStream->readShort(pImageExposure);
- fFilm = aStream->readShort(pImageFilm);
- fFocal = aStream->readShort(pImageFocal);
- fFStop = aStream->readShort(pImageFStop);
- fCamera = aStream->readLong(pImageCamera);
- fKeyCount = aStream->readShort(pImageKeyCount);
- if (fKeyCount) {
- aStream->openList(pImageKeys);
- for (index = 0; index < fKeyCount; index++)
- aStream->readString(fKeys[index], 33);
- aStream->closeList();
- if (index < kKeywords)
- fKeys[index][0] = 0; // set last key to null
- }
- aStream->readNativeString(fName, sizeof(fName), pName);
- aStream->readNativeString(fBy, sizeof(fBy), pImageBy);
- aStream->readNativeString(fDate, sizeof(fDate), pImageDate);
- aStream->readNativeString(fCatalog, sizeof(fCatalog), pImageCatalog);
- }
-
- /*
- * The writeObject method is used to write to the permanent data members of the
- * object from the given stream. In most cases, this method operates without concern
- * for the type of stream the data values are coming from. As a result, this method
- * is capable of writing to such diverse sources as the data fork of a file, a
- * resource fork, an AppleEvent, the clipboard, a memory block, and so on.
- *
- * The aTag argument indicates how much information to write to the stream.
- * It is sometimes sufficient to write out only those parts that are dirty. Other
- * times it is necessary to write all the data, as when doing Save As operation
- * or when communicating an object's complete state across and RPC channel.
- *
- * The two tag values that are currently used are kNeoObjectTag and kNeoAllTag.
- *
- * The value kNeoObjectTag means that only those values of immediate interest
- * need to be written to the stream, though implementations of writeObject may
- * write out additional data member values if they wish.
- *
- * The value kNeoAllTag indicates that all data member values for this class
- * should be writen out to the stream.
- */
- #pragma segment NeoWrite
- void CNDImage::writeObject(CNeoStream *aStream, const NeoTag aTag)
- {
- short index;
- CNDCamera * camera;
-
- NeoInherited::writeObject(aStream, 'PICT');
-
- aStream->writeShort(fExposure, pImageExposure);
- aStream->writeShort(fFilm, pImageFilm);
- aStream->writeShort(fFocal, pImageFocal);
- aStream->writeShort(fFStop, pImageFStop);
- aStream->writeLong(fCamera, pImageCamera);
- aStream->writeShort(fKeyCount, pImageKeyCount);
- if (fKeyCount) {
- aStream->openList(pImageKeys);
- for (index = 0; index < fKeyCount; index++)
- aStream->writeString(fKeys[index], 33);
- aStream->closeList();
- }
- aStream->writeNativeString(fName, sizeof(fName), pName);
- aStream->writeNativeString(fBy, sizeof(fBy), pImageBy);
- aStream->writeNativeString(fDate, sizeof(fDate), pImageDate);
- aStream->writeNativeString(fCatalog, sizeof(fCatalog), pImageCatalog);
-
- // If they asked for the camera explicitly, then send the camera object
- if (aTag == cCamera) {
- camera = getCamera();
- if (camera) {
- camera->writeObject(aStream, aTag);
- camera->unrefer();
- }
- }
- }
-
- /** Search Methods **/
- /*
- * Once an object is made permanent it can continue be treated like any other object,
- * including being disposed of. While disposing of an object involves elliminating a
- * reference to it (and in the process, deleting it from memory), disposing does not
- * affect object's permanent state in the file.
- *
- * Locating a permanent object in a file is very easy. In order to identify the
- * object (or objects) of interest its class and identity must be given. FindByID()
- * is also capable of using the specified class as a base class so that it and all
- * subclasses of the base class is searched to locate the object. If the given
- * identity is ambiguous, then the search may find more than one object. Passing
- * FindByID() an array will allow this function to return a list of all objects
- * found.
- */
- #pragma segment NeoSearch
- CNDImage *CNDImage::FindByName(CNeoDatabase *aDataBase, const NeoID aClassID, const CNeoString &aName, const Boolean aDeeply, NeoTestFunc1 aFunc, void *aParam, const NeoLockType aLock)
- {
- CNeoNameSelect key(aName);
- CNDImage * image;
-
- image = (CNDImage *)aDataBase->findObject(aClassID, &key, aDeeply, aFunc, aParam, aLock);
-
- return image;
- }
-
- /*
- * This function is applied to images that match a given selection criteria.
- * It adds the ID of the image to the specified array.
- */
- void *CNDImage::GetImageID(CNeoNode *aNode, const short aIndex, const NeoLockType aLock, void *aParam)
- {
- CNDImage * image;
-
- if (aIndex < 0)
- image = (CNDImage *)aNode;
- else
- NeoFailNil(image = (CNDImage *)aNode->getObject(aIndex));
-
- ((CArray *)aParam)->InsertAtIndex(&(image->fID), ((CArray *)aParam)->numItems +1);
-
- return 0;
- }
-
- /* Return a keyword select key that matches the specified keyword value.
- */
- CNeoKeywordSelect *CNDImage::GetKeywordKey(char *aKeyword)
- {
- short index;
- char keyword[33];
- CNeoKeywordSelect * key;
-
- /* Translate the keyword to lower case */
- for (index = 0; aKeyword[index]; index++)
- if (aKeyword[index] >= 'A' &&
- aKeyword[index] <= 'Z')
- keyword[index] = aKeyword[index] +32;
- else
- keyword[index] = aKeyword[index];
- keyword[index] = 0;
-
- NeoFailNil(key = new CNeoKeywordSelect(keyword));
-
- return key;
- }
-
- /*
- * The getValue method can be used to obtain the value of a data member of an
- * object. The aName argument is a tag which identifies the data member, and aType
- * refers to the format in which the value is to be returned. Finally, aValue is a
- * pointer to a buffer into which the value should be returned.
- */
- #pragma segment NeoSearch
- OSErr CNDImage::getValue(const NeoTag aName, const NeoTag aType, void *aValue)
- {
- OSErr err = noErr;
-
- switch (aName) {
- case pImageKeys:
- NeoAssert(aType == kNeoStringType);
- *(keyArrayPtr *)aValue = &fKeys;
- break;
-
- default:
- err = NeoInherited::getValue(aName, aType, aValue);
- }
-
- return err;
- }
-
- void CNDImage::draw(Rect *aRect)
- {
- // Null Method
- }
-
- CNDCamera *CNDImage::getCamera(void)
- {
- CNDCamera * camera = nil;
-
- if (fCamera)
- camera = (CNDCamera *)CNeoPersist::FindByID(gNeoDatabase, kNDCameraID, fCamera, FALSE);
-
- return camera;
- }
-
- void CNDImage::buildKeyWordStr(char *aString) /* construct single string from keywords array */
- {
- int index;
-
- aString[0] = 0;
-
- if(!fKeyCount)
- return;
-
- for (index = 0; index < fKeyCount; index++) {
- if(index)
- strcat(aString , ", "); /* separate strings with a comma */
- strcat(aString, fKeys[index]);
- }
- }
-
-
- /* parse comma delimited keywords string */
- void CNDImage::parseKeywords(char *str)
- {
- int i, j, kwIndex = 0;
- char ch;
-
- for (i = 0; i < kKeywords; i++) {
- if (!str[kwIndex]) /* don't go past end of valid characters */
- break;
- for (j = 0; j < 32; j++) {
- if (!str[kwIndex]) /* don't go past end of valid characters */
- break;
- ch = str[kwIndex++];
- if (ch == ',') { /* keys are comma delimited */
- for (; j >= 0; j--) /* trim trailing spaces */
- if (fKeys[i][j -1] != ' ')
- break;
- while((str[kwIndex] == ' ') &&
- str[kwIndex]) /* trim leading spaces */
- kwIndex++;
- break;
- }
- else
- fKeys[i][j] = ch;
- }
- fKeys[i][j] = 0; /* zero terminated string */
- }
- fKeyCount = i;
- if (fKeyCount < kKeywords)
- fKeys[fKeyCount][0] = 0; /* set last key to null */
- }
-
- /* ***************************** CNeoKeywordSelect **************************** */
-
- /* ****************************************************************** */
- /** Instance Methods **/
- /* ****************************************************************** */
- CNeoKeywordSelect::CNeoKeywordSelect(const char *aKeyword)
- : CNeoTypeSelect(pImageKeys)
- {
- setKeyword(aKeyword);
- }
-
- /*
- * While locating an object based on its fID value is the default way of
- * identifying an object, many other application-specific search criteria can
- * also be used.
- *
- * Compare the order of this object against the given key.
- *
- * This function should return one of the following;
- * kNeoLow - if the key refers to an object after the given one,
- * kNeoExact - if the key refers to the given object, or
- * kNeoHigh - if the key refers to an object before the given one.
- */
- #pragma segment NeoSearch
- NeoOrder CNeoKeywordSelect::compare(CNeoPersist *aObject, const short aIndex, NeoOrder *aKeyOrder) const
- {
- short index;
- short j;
- NeoOrder order;
- keyArrayPtr value;
- char * ptr;
- char word[33];
- CNDImage * image;
-
- if (fValue[0]) {
- if (aIndex < 0)
- aObject->getValue(fSelectType, kNeoStringType, &value);
- else
- ((CNeoNode *)aObject)->getEntryValue(aIndex, fSelectType, kNeoStringType, &value);
-
- order = kNeoLow;
- ptr = value[0][0];
- for (index = 0; index < kKeywords; index++) {
- /* Translate the keyword to lower case */
- if (ptr[0] == 0)
- break;
- for (j = 0; ptr[j]; j++)
- if (ptr[j] >= 'A' &&
- ptr[j] <= 'Z')
- word[j] = ptr[j] +32;
- else
- word[j] = ptr[j];
- word[j] = 0;
- ptr += 33;
- if (Neostrncmp(word, fValue, 32L) == 0) {
- order = kNeoExact;
- break;
- }
- }
-
- if (fOrder != kNeoExact &&
- (fOrder&order))
- order = kNeoExact;
- }
- else
- order = kNeoExact;
-
- *aKeyOrder = order;
-
- return *aKeyOrder;
- }
-
- /* ****************************************************************** */
- /** Accessing Methods **/
- /* ****************************************************************** */
- void CNeoKeywordSelect::getKeyword(char *aKeyword) const
- {
- NeoBlockMove(fValue, aKeyword, strlen(fValue) +1);
- }
-
- void CNeoKeywordSelect::setKeyword(const char *aKeyword)
- {
- NeoBlockMove(aKeyword, fValue, strlen(aKeyword) +1);
- }
-
-